package com.atzzy.ysmall.ysmall_userserviceimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atzzy.ysmall.ysmall_allService.UserService.UserCheck;
import com.atzzy.ysmall.ysmall_beans.Users;
import com.atzzy.ysmall.ysmall_common.utils.MD5Utils;
import com.atzzy.ysmall.ysmall_common.vo.R;
import com.atzzy.ysmall.ysmall_mapper.UserMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author JAVAZeng
 * @Date 2022/2/24 17:11
 * @Version 1.0
 */
@Service
@Component
public class UserCheckImpl implements UserCheck {
    @Resource
    private UserMapper userMapper;


    @Override
    public R checkUserBaseInfo(Users users) {
        Users user = userMapper.userSelectPhone(users.getUserMobile());
        System.out.println(user);
        if (user != null) {
            if (users.getUsername().equals(user.getUsername())) {
                return new R(201, "用户信息验证成功", users);
            } else {
                return new R(209, "用户名不正确", null);
            }
        } else {
            return new R(205, "用户电话信息不正确", null);
        }
    }

    @Override
    public R userResetPwd(Users users) {
        String password = users.getPassword();
        String newPwd = MD5Utils.md5(password);
        if (userMapper.updateUserPwd(users.getUsername(), newPwd)) {
            return new R(201, "密码重置成功", "SUCCESS");
        }
        return new R(509, "重置密码失败", null);
    }

    /**
     * 用户名重复验证接口
     */
    @Override
    public R checkUserName(String username) {
        if (userMapper.userLoginName(username) == null)
            return new R(201, "用户名可用", username);

        else return new R(501, "用户名不可用", null);
    }
}
